#include <windows.h>
#include "bitmap.h"
#include "open_file_dialog.h"
#include "bmp_reader.h"

static TCHAR szFilter[] = TEXT("Bitmap Files (*.BMP)\0*.bmp\0") \
	TEXT ("All Files (*.*)\0*.*\0\0");
static TCHAR szTitle[] = TEXT("Choose a Bitmap file, plz.");
static TCHAR szDefExt[] = TEXT("bmp");

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
					PSTR szCmdLine, int iCmdShow)
{
	OpenFileDialog openFileDialog;
	Bitmap* pBitmap;
	HWND hwnd;
	HDC hdc;
	do {
		OpenFileDialog_init(&openFileDialog, NULL, szFilter, szTitle, szDefExt);
		if (!OpenFileDialog_show(&openFileDialog)) {
			MessageBox(NULL, TEXT("File open failed."), TEXT("FATAL ERROR"), MB_OK | MB_ICONEXCLAMATION);
			continue;
		}

		pBitmap = Bitmap_new(openFileDialog.szFile);
	
		if (LockWindowUpdate(hwnd = GetDesktopWindow())) {
			hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
			Bitmap_show(pBitmap, hdc);
			Sleep(2012);
			LockWindowUpdate(NULL);
		}
	} while (MessageBox(NULL, TEXT("Want more?"), 
		TEXT("Bmp Reader"), MB_YESNO | MB_ICONINFORMATION) == IDYES);
	
	return 0;
}